#include <stdio.h>


int main ()
{
	int c, n, base, restar;

	c = getchar();
	while (c != '0')
	{
		base = 0;
		restar = 0;

		do
		{
			n = c - '0';
			base += n;
			base <<= 1;
			restar += n;

			c = getchar();
		}
		while (c != '\n');

		printf("%d\n", base - restar);
		c = getchar();
	}

	return 0;
}